using IQIGame.Onigao.Framework;

namespace IQIGame.Onigao.GamePlay
{
    [SerializableGroup(SerializableGroup.LevelModuleConfig)]
    public partial class ElevatorFloorData
    {
        public Vector3Int position;
        public long fenceOffset;
        public long fenceWidth;
        public bool isActive;

        /// <summary>
        /// 获取单方向上围栏偏移
        /// </summary>
        /// <param name="dirIndex">0-3，代表z正方向开始顺时针4个方向，（+z, +x, -y, -z）</param>
        /// <returns></returns>
        public ushort GetFenceOffset(byte dirIndex)
        {
            return GetQuarterIntFromLong(fenceOffset, dirIndex);
        }

        /// <summary>
        /// 获取单方向上围栏宽度
        /// </summary>
        /// <param name="dirIndex">0-3，代表z正方向开始顺时针4个方向，（+z, +x, -z, -x）</param>
        /// <returns></returns>
        public ushort GetFenceWidth(byte dirIndex)
        {
            return GetQuarterIntFromLong(fenceWidth, dirIndex);
        }

        private ushort GetQuarterIntFromLong(long l, byte index)
        {
            if (index != 0 && index != 1 && index != 2 && index != 3)
            {
                LogGame.LogError("[Share] index只支持0-3");
                return 0;
            }
            // 计算要提取的位的位置
            int shiftAmount = index * 16;
            // 通过右移和按位与操作提取8位数字
            return (ushort)((l >> shiftAmount) & 0xFFFF);
        }
    }
}
